﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KerriganDirection.DirectionServiceWCF;
using System.Diagnostics;
using KerriganDirection.Helpers;
using System.Windows.Controls;
using System.ComponentModel;

namespace KerriganDirection.VehicleMgt
{
    public class VehicleModule: INotifyPropertyChanged
    {
        #region NotifyPropertyChanged

        public event PropertyChangedEventHandler PropertyChanged;

        private void OnPropertyChanged(string property)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(property));
            }
        }

        #endregion

        #region Properties

        private VehicleDC _VehicleVO;
        public VehicleDC VehicleVO 
        {
            get
            {
                return this._VehicleVO;
            }
            set
            {
                this._VehicleVO = value;
                OnPropertyChanged("VehicleVO");
            }
        }

        private MainModule _MainModuleVO;
        public MainModule MainModuleVO 
        {
            get
            {
                return this._MainModuleVO;
            }
            set
            {
                this._MainModuleVO = value;
                OnPropertyChanged("MainModuleVO");
            }
        }

        private ucAddVehicle _UcAddVehicleVO;
        public ucAddVehicle UcAddVehicleVO 
        {
            get
            {
                return this._UcAddVehicleVO;
            }
            set
            {
                this._UcAddVehicleVO = value;
                OnPropertyChanged("UcAddVehicleVO");
            }
        }

        public ucEditVehicle _UcEditVehicleVO;
        public ucEditVehicle UcEditVehicleVO 
        {
            get
            {
                return this._UcEditVehicleVO;
            }
            set
            {
                this._UcEditVehicleVO = value;
                OnPropertyChanged("UcEditVehicleVO");
            }
        }

        private ucVehiclesList _UcVehicleListVO;
        public ucVehiclesList UcVehicleListVO 
        {
            get
            {
                return this._UcVehicleListVO;
            }
            set
            {
                this._UcVehicleListVO = value;
                OnPropertyChanged("UcVehicleListVO");
            }
        }

        private ucVehicleOptions _UcVehicleOptionsVO;
        public ucVehicleOptions UcVehicleOptionsVO
        {
            get
            {
                return this._UcVehicleOptionsVO;
            }
            set
            {
                this._UcVehicleOptionsVO = value;
                OnPropertyChanged("UcVehicleOptionsVO");
            }
        }

        private vwGetVehicle[] _ListVehiclesVO;
        public vwGetVehicle[] ListVehiclesVO
        {
            get
            {
                return this._ListVehiclesVO;
            }
            set
            {
                this._ListVehiclesVO = value;
                OnPropertyChanged("ListVehiclesVO");
            }
        }

        private TypeVehicleDC[] _ListTypeVehicleVO;
        public TypeVehicleDC[] ListTypeVehicleVO
        {
            get
            {
                return this._ListTypeVehicleVO;
            }
            set
            {
                this._ListTypeVehicleVO = value;
                OnPropertyChanged("ListTypeVehicleVO");
            }
        }

        private vwGetVehicleAvailability[] _ListVehiclesAvailabilityVO;
        public vwGetVehicleAvailability[] ListVehiclesAvailabilityVO
        {
            get
            {
                return this._ListVehiclesAvailabilityVO;
            }
            set
            {
                this._ListVehiclesAvailabilityVO = value;
                OnPropertyChanged("ListVehiclesAvailabilityVO");
            }
        }

        #endregion

        #region Contructors

        public VehicleModule()
        {
        }

        #endregion

        #region Methods

        public void InitModule()
        {
            try
            {
                this.MainModuleVO = (App.Current.Windows[0] as MainWindow).MainModuleVO;

                RefreshList();

                this.UcVehicleListVO = new ucVehiclesList();
                this.UcVehicleOptionsVO = new ucVehicleOptions();
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }

        public void RefreshList()
        {
            //Initialization List
            //this.GetListVehicle();
            this.GetListVehicleAvailability();
            this.GetListTypeVehice();
        }

        public void SetVehicle()
        {
            try
            {
                ServiceProxy.Service.SetVehicle(this.VehicleVO);
                this.VehicleVO = new VehicleDC();
                this.MainModuleVO.GoToLitVehicle() ;
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }

        public void DeleteVehicle(int id)
        {
            try
            {
                ServiceProxy.Service.DeleteVehicle(id);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }

        public void GetVehicle(int IdVehicle)
        {
            try
            {
                this.VehicleVO = ServiceProxy.Service.GetVehicle(IdVehicle);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }

        public void GetListTypeVehice()
        {
            try
            {
                this.ListTypeVehicleVO = ServiceProxy.Service.GetListTypeVehicle();
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }

        public void GetListVehicle()
        {
            try
            {
                this.ListVehiclesVO = ServiceProxy.Service.GetListVehiclesToDisplay();
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }

        public void GetListVehicleAvailability()
        {
            try
            {
                this.ListVehiclesAvailabilityVO = ServiceProxy.Service.GetListVehiclesAvailabilityToDisplay();
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }

        #endregion
    }
}